package com.nondo.rdp.finance.endpoint.api.app;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.nondo.rdp.auth.endpoint.model.Page;
import com.nondo.rdp.auth.endpoint.model.Query;
import com.nondo.rdp.core.model.View;
import com.nondo.rdp.finance.domain.HotSearch;
import com.nondo.rdp.finance.service.HotSearchService;

@RestController("apiAppHotSearch")
@RequestMapping("/api/app/hotSearch")
public class HotSearchEndpoint {
    @Autowired
    HotSearchService hotSearchService;
    
    /**
     * 查看热门搜索
     * @param request
     * @param response
     * @param id
     * @return
     */
    @RequestMapping("/info/{id}")
	public View info(HttpServletRequest request, HttpServletResponse response,
			@PathVariable("id") Long id) {
		View<HotSearch> view = new View<HotSearch>(20000, "获取数据成功");
		
		HotSearch hotSearch = null;
		if (id != null) {
			hotSearch = hotSearchService.findOne(id);
		} else {
			hotSearch = new HotSearch();
		}

		view.setData(hotSearch);
		return view;
	}
    
    /**
     * 获取热门搜索列表
     * @param request
     * @param response
     * @param query
     * @return
     */
    @RequestMapping("/list")
    public View<Page> list(HttpServletRequest request, HttpServletResponse response, @RequestBody Query<HotSearch> query) {
        View<Page> view = new View(20000, "获取列表成功");

        HotSearch hotSearch = query.getData();

        Page<HotSearch> page = hotSearchService.findAll(new Page<HotSearch>(query.getPage(), query.getSize()), hotSearch);

        view.setData(page);

        return view;
    }

}